/// User usecase
/// 编排领域对象的操作流程完成实际的业务流程
use std::rc::Rc;
pub struct UserAction {
    user_repository: Rc<Box<dyn crate::domain::user::repository::UserRepository>>,
}
impl UserAction {
    pub fn new(
        user_repository: Rc<Box<dyn crate::domain::user::repository::UserRepository>>,
    ) -> Self {
        Self { user_repository }
    }

    pub fn update_info(&mut self, user: crate::domain::user::entity::User) -> Result<(), String> {
        let mut save_user =
            crate::domain::user::aggregate::SaveUser::new(self.user_repository.clone());
        save_user.find_by_id(user.id.clone());
        if !save_user.exist() {
            return Err("User not found".to_string());
        }
        save_user.save()
    }
}
